Better Circle Scanning#910
Open
Stick404 wants to merge 2 commits into
Open
Conversation
…`ServerChunkCache#getChunkFuture`
Closed
107cf95 to
7202ed7
Compare
s5bug
reviewed
May 10, 2026
Comment on lines
+24
to
+57
| fun cacheChunk(chunk: ChunkPos): Boolean { | ||
| val chunkLong = chunk.toLong() | ||
| // We have the chunk already, so we can skip it | ||
| if (chunks.contains(chunkLong)){ | ||
| return true | ||
| } | ||
| val future = level.chunkSource.getChunkFuture(chunk.x,chunk.z, ChunkStatus.EMPTY,true).get() | ||
| if (future.left().isPresent){ | ||
| chunks.put(chunkLong, future.left().get() as ImposterProtoChunk) | ||
| return true | ||
| } | ||
| HexAPI.LOGGER.warn("Failed to get chunk at {}!",chunk) | ||
| return false | ||
| } | ||
|
|
||
| fun cacheChunk(chunk: Long): Boolean{ | ||
| return cacheChunk(ChunkPos(chunk)) | ||
| } | ||
|
|
||
| fun getBlock(blockPos: BlockPos): BlockState? { | ||
| val chunkPos = ChunkPos(blockPos).toLong() | ||
| if (!cacheChunk(chunkPos)){ | ||
| return null | ||
| } | ||
| return chunks.get(chunkPos).getBlockState(blockPos) | ||
| } | ||
|
|
||
| fun getBlockEntity(blockPos: BlockPos): BlockEntity? { | ||
| val chunkPos = ChunkPos(blockPos).toLong() | ||
| if (!cacheChunk(chunkPos)){ | ||
| return null | ||
| } | ||
| return chunks.get(chunkPos).getBlockEntity(blockPos) | ||
| } |
Contributor
There was a problem hiding this comment.
Suggested change
| fun cacheChunk(chunk: ChunkPos): Boolean { | |
| val chunkLong = chunk.toLong() | |
| // We have the chunk already, so we can skip it | |
| if (chunks.contains(chunkLong)){ | |
| return true | |
| } | |
| val future = level.chunkSource.getChunkFuture(chunk.x,chunk.z, ChunkStatus.EMPTY,true).get() | |
| if (future.left().isPresent){ | |
| chunks.put(chunkLong, future.left().get() as ImposterProtoChunk) | |
| return true | |
| } | |
| HexAPI.LOGGER.warn("Failed to get chunk at {}!",chunk) | |
| return false | |
| } | |
| fun cacheChunk(chunk: Long): Boolean{ | |
| return cacheChunk(ChunkPos(chunk)) | |
| } | |
| fun getBlock(blockPos: BlockPos): BlockState? { | |
| val chunkPos = ChunkPos(blockPos).toLong() | |
| if (!cacheChunk(chunkPos)){ | |
| return null | |
| } | |
| return chunks.get(chunkPos).getBlockState(blockPos) | |
| } | |
| fun getBlockEntity(blockPos: BlockPos): BlockEntity? { | |
| val chunkPos = ChunkPos(blockPos).toLong() | |
| if (!cacheChunk(chunkPos)){ | |
| return null | |
| } | |
| return chunks.get(chunkPos).getBlockEntity(blockPos) | |
| } | |
| fun cacheChunk(chunk: ChunkPos): ImposterProtoChunk? { | |
| val chunkLong = chunk.toLong() | |
| // If we have the chunk already, we can skip fetching it | |
| val existing = chunks.get(chunkLong) | |
| if (existing != null){ | |
| return existing | |
| } | |
| val future = level.chunkSource.getChunkFuture(chunk.x,chunk.z, ChunkStatus.EMPTY,true).get() | |
| if (future.left().isPresent){ | |
| val next = future.left().get() as ImposterProtoChunk | |
| chunks.put(chunkLong, next) | |
| return next | |
| } | |
| HexAPI.LOGGER.warn("Failed to get chunk at {}!",chunk) | |
| return null | |
| } | |
| fun cacheChunk(chunk: Long): ImposterProtoChunk? { | |
| return cacheChunk(ChunkPos(chunk)) | |
| } | |
| fun getBlock(blockPos: BlockPos): BlockState? { | |
| val chunkPos = ChunkPos(blockPos).toLong() | |
| return cacheChunk(chunkPos)?.getBlockState(blockPos) | |
| } | |
| fun getBlockEntity(blockPos: BlockPos): BlockEntity? { | |
| val chunkPos = ChunkPos(blockPos).toLong() | |
| return cacheChunk(chunkPos)?.getBlockEntity(blockPos) | |
| } |
| } | ||
| val future = level.chunkSource.getChunkFuture(chunk.x,chunk.z, ChunkStatus.EMPTY,true).get() | ||
| if (future.left().isPresent){ | ||
| chunks.put(chunkLong, future.left().get() as ImposterProtoChunk) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improves Spell Circle scanning by making a custom system to use
ServerChunkCache#getChunkFuture's quicker chunk loading.Creates a Helper Class in case spells/addons wish to use this system